package com.utils.search;

import com.dataModel.Ayah;
import com.dataModel.Quran;
import com.dataModel.Sourah;
import com.dataModel.descriptors.AyahDescriptor;

public class QuranSearcher {
	
	public static SearchResults search(String searchPattern)
	{
		SearchResults searchResults=new SearchResults();
		searchResults.setSearchPattern(searchPattern);
	//	long startTime=System.currentTimeMillis();
	
		for(int i=0;i<Quran.SOWAR_NUMBER;i++)
		{
		Sourah sourah=	Quran.getSowar()[i];
		
		for(int j=0;j<sourah.getAyat().size();j++)
		{
			Ayah ayah=sourah.getAyat().get(j);
			String searchAyahText=ayah.getText();
			
			if(searchAyahText.contains(searchPattern))
			{
				//System.out.println((i+1)+","+(j+1));
				searchResults.getMatchedAyat().add(new AyahDescriptor(i+1,j+1));
			}
		}
		}
	//	long endTime=System.currentTimeMillis();
	//	double searchTime=endTime-startTime;
	//	System.out.println("found "+searchResults.getMatchedAyat().size()+" matched ayah in"+searchTime);
		return searchResults;
	}

}
